package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.EsService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听日志队列的数据
 * @author lenovo
 * @version V1.0
 * @Date 2021/11/25 11:43
 */
@Component
@Slf4j
public class ReciveLogListener {

    @Autowired
    private EsService esService;

    /**
     * 监听推送日志的队列，将日志发送给es服务器
     * @param message
     * @param channel
     * @param standardSubmit
     */
    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void messageHandler(Message message, Channel channel, StandardSubmit standardSubmit) throws Exception{
        //1.接收submit对象.存到es服务器中
        esService.add(standardSubmit);

        //2.手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }

}
